<?php
require $_SERVER['DOCUMENT_ROOT'].'/../_core/common.php';

$msg = array('error'=>true);

//权限验证
if( Role::init() == false ){
	$msg['error'] = false;
	$myjson = json_encode($msg); 
	echo $myjson; 
	exit;
}

$db = new DB('news');

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$orders = isset($_POST['orders']) ? intval($_POST['orders']) : 0;
$title = isset($_POST['title']) ? h($_POST['title']) : '';
$url = isset($_POST['url']) ? h($_POST['url']) : '';
$updated = time();

$sql = 'select id from relative_news where id='.$id.' and is_del=1 limit 1';
$rs = $db->query($sql)->getOne();

//检验必要参数
if( $rs['id'] < 1 || $title == '' || $url == '' ){
	$msg['error'] = false;
}else{
	//组装news的insert数组
	$data=array('title'=>$title,
				'orders'=>$orders,
				'url'=>$url,
				'updated'=>$updated,
				);
	$db->table('relative_news')->where('id='.$id)->update($data)->run();
	
	//记录动作日志
	Log::logs_articles(-2, 3, $rs['id'], $title);

}

$myjson = json_encode($msg); 
echo $myjson; 
exit;